<?php
include_once dirname(__FILE__)."/../../model/config.php";
		$_phase_desc=new phase_desc();
if(isset($_POST["operation"])){
if($_POST["operation"]=="INSERT"){
		if(isset($_POST["id_phase_desc"])){$_phase_desc->set_id_phase_desc($_POST["id_phase_desc"]);}
		if(isset($_POST["titre"])){$_phase_desc->set_titre($_POST["titre"]);}
		if(isset($_POST["description"])){$_phase_desc->set_description($_POST["description"]);}
		if(isset($_POST["type_envoi"])){$_phase_desc->set_type_envoi($_POST["type_envoi"]);}
		$res=$_phase_desc->INSERT(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}
elseif($_POST["operation"]=="DELETE"){
		if(isset($_POST["id_phase_desc"])){
		$_phase_desc->set_id_phase_desc($_POST["id_phase_desc"]);
		$res=$_phase_desc->DELETE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
		}
}
elseif($_POST["operation"]=="UPDATE"){
		if(isset($_POST["id_phase_desc"])){$_phase_desc->set_id_phase_desc($_POST["id_phase_desc"]);}
		if(isset($_POST["titre"])){$_phase_desc->set_titre($_POST["titre"]);}
		if(isset($_POST["description"])){$_phase_desc->set_description($_POST["description"]);}
		if(isset($_POST["type_envoi"])){$_phase_desc->set_type_envoi($_POST["type_envoi"]);}
		$res=$_phase_desc->UPDATE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}

}
else{
	$constraint='';$limit=0;$start=0;$pagination='';
	if(isset($_POST["id_phase_desc"]) && !empty($_POST["id_phase_desc"])){
		$constraint.=" AND id_phase_desc='".$_POST["id_phase_desc"]."'";
	}

	if(isset($_POST["titre"]) && !empty($_POST["titre"])){
		$constraint.=" AND titre='".$_POST["titre"]."'";
	}

	if(isset($_POST["description"]) && !empty($_POST["description"])){
		$constraint.=" AND description='".$_POST["description"]."'";
	}

	if(isset($_POST["type_envoi"]) && !empty($_POST["type_envoi"])){
		$constraint.=" AND type_envoi='".$_POST["type_envoi"]."'";
	}

	if(isset($_POST['limit'])){$limit=$_POST['limit'];}
	if(isset($_POST['start'])){$start=$_POST['start'];}
	if($limit>0){
		$pagination.=" LIMIT  $start,$limit"; 
}
		$res=$_phase_desc->SELECT($constraint,$pagination); 

		 $data=array();
		  while($row=$_phase_desc->fetch_object()){
		  	$data[]=$row;
	  	  }
  	 	 
		
	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('totalcount' => count($data),'result' => $data ));
	  	
	  }}
?>